home *** CD-ROM | disk | FTP | other *** search
- #!perl
-
-
- # index.cgi
-
- # Displays an index of the directory
- #
- # by Mark Tearle 1996
- # Stairways Software Pty Ltd
- #
- # Email: <mtearle@stairways.com.au>
- #
- # This script based on code by Peter Lewis and the PCGI example
- #
-
- # You will need to change this, if you put index.cgi in the root directory of your web site this can
- # just be ""
-
- $rootdir="Crazy:Pub:CGI Examples";
-
- sub unixpath2macpath {
- local($path) = @_;
-
- $path =~ tr+/+:+;
- # $path = ":$path";
- $path;
- }
-
-
- sub getlocallisting {
- local($base) = @_;
- local(@list,$file,@names);
-
-
- if ($base eq "/") {
- $base = "";
- }
-
- chdir &unixpath2macpath($base) || die "Couldn't change directory $!";;
-
- @list = ();
- opendir(DIR, &unixpath2macpath($base)) || die "Couldn't open directory $!";
- @names = readdir(DIR);
- closedir(DIR);
- foreach $name (@names) {
- next if $name =~ /^\./;
- $file = "$name";
- push(@list,"$file");
-
- }
-
- @list;
- }
-
- sub getbasename {
- local ($tmp);
-
- $tmp = $ENV{"SCRIPT_NAME"};
- $tmp =~ /(.*)\/(.*)/;
-
- $tmp = $1;
- if ($tmp eq "") {
- $tmp="/";
- } else {
- $tmp="$tmp/";
- }
- }
-
- sub getparent {
- local ($tmp) = @_;
-
- $tmp =~ /(.*)\/(.*)/;
-
- $tmp = $1;
- if ($tmp eq "") {
- $tmp="/";
- } else {
- $tmp="$tmp/";
- }
- }
-
-
- $servername = "NetPresenz/4.0";
-
- $eol = "\015\012"; # Give CRLF terminated headers
-
- if ($header) {
- print "HTTP/1.0 200 OK$eol";
- print "Server: ";
- print $servername;
- print "$eol";
- print "MIME-Version: 1.0$eol";
- }
- print "Content-Type: text/html$eol$eol";
-
-
- $basename = &getbasename();
-
-
- print"<HEAD><TITLE>http://";
- print $ENV{"SERVER_NAME"};
- if ($ENV{"SERVER_PORT"} ne "80") {
- print ":";
- print $ENV{"SERVER_PORT"};
- }
- print "$basename";
-
- print <<END_HEADER;
- </TITLE></HEAD>
-
- <BODY>
- <PRE>
- END_HEADER
-
-
-
- print "<H2>Index of $basename</H2>$eol";
- print "<UL>$eol";
-
- if ($rootdir eq "") {
- $rootdir=`pwd`;
- chomp $rootdir;
- }
-
- $dirname="$rootdir$basename";
-
- @locallist = &getlocallisting($dirname);
- foreach $i (sort @locallist) {
- print "<LI>";
- print "<A HREF=\"http://";
- print $ENV{"SERVER_NAME"};
- if ($ENV{"SERVER_PORT"} ne "80") {
- print ":";
- print $ENV{"SERVER_PORT"};
- }
- print "$basename";
- print "$i\">";
- print "$i";
- print "</A>$eol";
- }
-
- if ($basename ne "/") {
- $mytmp = $basename;
- chop $mytmp;
- print "<LI>";
- print "<A HREF=\"http://";
- print $ENV{"SERVER_NAME"};
- if ($ENV{"SERVER_PORT"} ne "80") {
- print ":";
- print $ENV{"SERVER_PORT"};
- }
- print &getparent($mytmp);
- print "\">";
- print "<I>Parent Directory</I>";
- print "</A>$eol";
- }
-
- print "</UL>$eol";
-
- print "<I>";
- print $servername;
- print "</I>$eol";
-
- print <<END_FOOTER;
- </PRE>
- </BODY>
- END_FOOTER
-
-